package threadLock.threadBasics;

/**
 * yield 让出时间片
 */
public class YieldThread implements Runnable{

    public YieldThread(){
        Thread thread = new Thread(this);
        thread.start();
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            if ((i % 5 )== 0) {
                System.out.println(Thread.currentThread() + "yield cpu ...");
                Thread.yield();
            }
        }
        System.out.println(Thread.currentThread() + "is over");
    }

    public static void main(String[] args) {
        new YieldThread();
        new YieldThread();
        new YieldThread();
    }
}
